package org.jeecg.modules.order.service.impl;


import org.jeecg.common.util.DateUtil;
import org.jeecg.modules.order.entity.BeienOrder;
import org.jeecg.modules.order.entity.BeienProcessDetail;
import org.jeecg.modules.order.entity.BeienProcessRelation;
import org.jeecg.modules.order.mapper.BeienOrderMapper;
import org.jeecg.modules.order.service.IBeienOrderService;
import org.jeecg.modules.order.service.IBeienProcessDetailService;
import org.jeecg.modules.order.service.IBeienProcessRelationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import java.util.Date;
import java.util.List;

/**
 * @Description: beien_order
 * @Author: jeecg-boot
 * @Date:   2024-11-18
 * @Version: V1.0
 */
@Service
public class BeienOrderServiceImpl extends ServiceImpl<BeienOrderMapper, BeienOrder> implements IBeienOrderService {

    @Autowired
    IBeienProcessRelationService relationService;

    @Autowired
    IBeienProcessDetailService detailService;


    /**
     * 生成计划
     * 1.根据订单关联的工艺路线查询出对应的工序，
     * 2.根据工序的日期算出计划完成的日期。(周天排除)
     * 3显示出日期，可调整。
     * @param id
     *
     */


    @Override
    public void createPlanOrder(String id) {
     BeienOrder  order =  this.getById(id);
     Date beginDate = order.getOrderCreateTime();
     Date timeDate =beginDate;
     List<BeienProcessRelation> relationList =relationService.selectByMainId("1859061351452934145");
      for(BeienProcessRelation bean: relationList){
          BeienProcessDetail  planDetail =  new BeienProcessDetail();
          if(bean.getStepId().equals("001")){
              planDetail.setRealBeginDate(beginDate);
          }
          planDetail.setOrderId(order.getOrderId());
          planDetail.setStepId(bean.getStepId());
          planDetail.setPlanBeginDate(timeDate);
          timeDate =DateUtil.addDay(timeDate,bean.getPrecessNum());
          planDetail.setPlanEndDate(timeDate);
          detailService.save(planDetail);
      }

    }
}
